﻿@using NorthWind.Models

@model List<Customer>
@{
    ViewBag.Title = "Index";
}

<h2>Liste des clients</h2>

@Html.ActionLink("Ajouter un client", "Create")

<br/>
<br/>


<table style="width:100%;">
    <tr>
        <th>Nom de la compagnie</th>
        <th>Nom du contact</th>
        <th>Fournisseur</th>
        <th>Téléphone</th>
    </tr>


    @foreach (Customer customer in Model)
    {
        foreach (var pairOfCustomer in ViewBag.supplierOfCustomer)
        {

            if (customer.CustomerID.Equals(pairOfCustomer.Key))
            {
                <tr>
                    <td>@customer.CompanyName</td>
                    <td>@customer.ContactName</td>
                    <td>
                        @{Dictionary<string, int> dico = new Dictionary<string, int>();}
                        @foreach (var pairSupplier in pairOfCustomer.Value)
                        {
                            foreach(var value in pairSupplier.Key)
                            {
                                if (!dico.ContainsKey(value.Key + "(" + pairSupplier.Value + " commande(s))"))
                                {
                                    dico.Add(value.Key + "(" + pairSupplier.Value +" commande(s))", value.Value);
                                }
                                    
                            }                                                
                                
                        }
                        @Html.ListBox("SuppliersOfClients", new SelectList(dico, "Value", "Key"), new { size = 5 })
                    </td>

                    <td>@customer.Phone</td>
                    
                    @* actions *@
                    <td>@Html.ActionImage("Details", new {id = customer.CustomerID}, "~/Content/Images/detail.png", "Detail")</td>
                    <td>@Html.ActionImage("Edit", new {id = customer.CustomerID}, "~/Content/Images/edit.png", "Modifier")</td>
                    <td>@Html.ActionImage("Delete", new {id = customer.CustomerID}, "~/Content/Images/delete.png", "Supprimer")</td>
                </tr>
            }
                
        }
    }
</table>

<br/>
@if (ViewBag.HasPreviousPage)
{
    @Html.ActionImage("Index", new { page = (ViewBag.PageIndex-1) }, "~/Content/Images/previous.png", "Précédent")
}

@if (ViewBag.HasNextPage)
{
    @Html.ActionImage("Index", new { page = (ViewBag.PageIndex + 1) }, "~/Content/Images/next.png", "Suivant")
}   